feat(mcp): add rank-tracking keyword write tools - #196
Open
Despiram wants to merge 1 commit into
Open
Conversation
Add add_rank_tracking_keywords and remove_rank_tracking_keywords MCP tools so agents can manage a rank tracker's watchlist, not just read it via get_rank_tracker. Both tools call the existing RankTrackingService (no duplicated business logic), scope access through withMcpProjectAuth, and resolve the tracker automatically when the project has exactly one. Adding reports added/duplicate/limit-skipped keywords and triggers no check (no credits spent); removing matches keywords case-insensitively and reports unmatched ones. Tools are listed on the AI/MCP settings page. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Self-hosted agents can already read the rank tracker over MCP (
get_rank_tracker), but they cannot manage its watchlist — adding or pruning tracked keywords still requires the dashboard. This enables agent-driven keyword management: an agent doing keyword research over MCP can now promote its findings straight into the tracker (and clean up stale ones) without a human round-trip.What this adds
add_rank_tracking_keywords— adds keywords (1–100) to a project's rank tracker. Reports added, already-tracked (duplicate), and cap-skipped keywords. Uses no credits and triggers no check; positions appear on the next scheduled or dashboard-triggered check.remove_rank_tracking_keywords— removes keywords from the watchlist, matching case-insensitively after trimming (the stored normal form). Unmatched keywords are reported rather than erroring. MarkeddestructiveHint: true.trackerIdand resolve the tracker automatically when the project has exactly one; with several trackers, the error lists them so the agent can pick.RankTrackingService.addKeywords/removeKeywords— no duplicated business logic — and are scoped throughwithMcpProjectAuthlike the other project tools.src/server/mcp/server.tsand listed on the AI/MCP settings page (AvailableTools).Intentionally left out: auto-triggering a rank check after adding (the server-function path does this for the dashboard). An MCP write should not silently spend credits; the tool says so in its output text instead.
How it was tested
src/server/mcp/tools/rank-tracking-write-tools.test.ts(7 tests) following the existing tool-test pattern: service pass-through + duplicate reporting, single-tracker resolution, multi-tracker/unknown-tracker rejection before any write, cap-skip reporting, keyword→ID mapping on remove, and no service call when nothing matches.pnpm test— 95 files, 775 tests, all passing.knip,tsc --noEmit(main + badseo), andoxlint . --type-awareall clean; new/touched files formatted with Prettier. (Repo-wideprettier --checkfails on this Windows checkout due to CRLF conversion, unrelated to this change.)🤖 Generated with Claude Code